package com.lostsheep.controller;

import com.lostsheep.service.UserService;
import com.lostsheep.service.feign.FeignUserService;
import com.lostsheep.vo.UserVO;
import com.zhongshi.framework.common.vo.CommonResult;
import com.zhongshi.puppy.service.sms.dto.SingleSendSmsDTO;
import com.zhongshi.puppy.sms.rpc.SmsRpcService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <b><code>UserController</code></b>
 * <p/>
 * Description
 * <p/>
 * <b>Creation Time:</b> 2024/7/6.
 *
 * @author dengzhen
 * @since spring-cloud-dubbo
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;
    
    @DubboReference
    private SmsRpcService smsRpcService;
    
    @Resource
    private FeignUserService feignUserService;

    @GetMapping("/rpc")
    public UserVO getUser(@RequestParam("id") Long id) {
        return userService.getUser(id);
    }

    @GetMapping("/rpc/list")
    public List<UserVO> getUsers() {
        return userService.getUsers();
    }
    
    @GetMapping("/rpc/sms")
    public void rpcRequest() {
        SingleSendSmsDTO singleSendSmsDTO = new SingleSendSmsDTO();
        singleSendSmsDTO.setPhoneNumbers("13413684909");
        CommonResult<Boolean> booleanCommonResult = smsRpcService.sendSmsCaptcha(singleSendSmsDTO);
        log.info("rpcRequest result:{}", booleanCommonResult);
    }
    
    @GetMapping("/rest/{id}")
    public UserVO getUserV2(@PathVariable("id") Long id) {
        return feignUserService.getUser(id);
    }
    
    @GetMapping("/rest/list")
    public List<UserVO> getUsersV2() {
        return feignUserService.listUsers();
    }
}
